package com.niuma.servlet;

import com.niuma.util.Constants;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 一颗蛋50斤
 */
public class HuaServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userCode = req.getParameter("userCode");

        if (userCode.equals(Constants.HUA_CODE)) {
            req.getSession().setAttribute(Constants.USER_SESSION, Constants.HUA_CODE);
            resp.sendRedirect("sys/huaPage.jsp");
        } else if (userCode.equals(Constants.YUN_CODE)) {
            req.getSession().setAttribute(Constants.USER_SESSION, Constants.YUN_CODE);
            resp.sendRedirect("sys/yunPage.jsp");
        } else {
            req.setAttribute("error", "密钥错误");
            req.getRequestDispatcher("/jsp/hua_login.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
